import java.util.ArrayList;

public class RRScheduler extends AbstractScheduler {
	public final int FINALTIMEQUANTUM = 5;

	public RRScheduler(ArrayList<Process> queue) {
		super(queue);
	}

	@Override
	public ScheduleProcess getProcess() {
		//
		if(super.queue.isEmpty()){
			return null;
		}
		
		Process process = super.queue.get(0);
		return new ScheduleProcess(process, (long) this.FINALTIMEQUANTUM);
	}
	
	public static void main(String[] args){
		ArrayList<Process> queue = new ArrayList<Process>();
		IScheduler scheduler = new RRScheduler(queue);
		ArrayList<ProcessArrival> processArrivalList = new ReadProcesses().read("TestProcesses.txt");
		
		for(ProcessArrival thisArrival: processArrivalList){
			queue.add(thisArrival.getProcess());
		}
		
		while(queue.size() > 0){
			Process localProcess = scheduler.getProcess().Process;
			System.out.println(queue.indexOf(localProcess));
			queue.remove(localProcess);
		}
	}
}
